// pages/appointment/clientment/yetment.js
const app = getApp();
var comm = require('../../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        loading: true,//上拉变量
        loadingconflg: false, //没有数据时变量,
        nodata: false,//无数据
        screen: [
            {
                title: "全部",
                id: 0,
                isshow: true
            },
            {
                title: "待接受",
                id: 1,
                isshow: false
            },
            {
                title: "进行中",
                id: 2,
                isshow: false
            },
            {
                title: "已完成",
                id: 4,
                isshow: false
            },
        ],
        status: 0,
        page: 1,
        totalpage: 1,//总页数
        listdata: [],
        colorlist: ["", "c-yellow", "c-purple", "c-red", "c-green", "c-9"]//状态颜色
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.setNavigationBarTitle({
            title: '预约记录',
        })
        var _this = this;
        _this.GetList(0);
    },
    //状态筛选
    screen: function (e) {
        console.log(e);
        var dataset = e.currentTarget.dataset;
        var screen = this.data.screen;
        for (var i = 0; i < screen.length; i++) {
            if (i == parseInt(dataset.index)) {
                screen[i].isshow = true;
            } else {
                screen[i].isshow = false;
            }
        }
        this.setData({
            "status": dataset.id,
            "page": 1,
            "screen": screen
        });
        this.GetList(1);
    },
    //获取列表
    GetList: function (tp) {
        wx.showLoading({
            title: '加载中',
        })
        var _this = this;
        var page = _this.data.page;
        var status = _this.data.status;
        var listdata = _this.data.listdata;
        app.http.POST("/MiniCardReserva/GetMyReservaRecord", { "status": status, "page": page }, (err, data) => {
            if (data.code == 1) {
                if (data.data.List == null || data.data.List.length < 1) {
                    listdata = tp == 1 ? [] : listdata;
                    _this.setData({
                        "loading": false,
                        "loadingconflg": false,
                        "nodata": true,
                        "listdata": listdata
                    })
                } else {
                    var list = data.data.List;
                    for (var i = 0; i < data.data.List.length; i++) {
                        list[i].CTime = comm.dateFormat(list[i].CTime, "yyyy-MM-dd");
                        list[i].ReTime = comm.dateFormat(list[i].ReTime, "yyyy-MM-dd hh:mm");
                    }
                    if (tp == 0) {
                        listdata = listdata.concat(list);
                    }
                    if (tp == 1) {
                        listdata = list;
                    }
                    _this.setData({
                        "listdata": listdata,
                        "totalpage": data.data.PageCount,
                        "loading": false,
                        "loadingconflg": false,
                        "nodata": false
                    })
                }
            } else {
                wx.showToast({
                    title: '获取列表失败',
                    icon: 'none',
                    duration: 2000
                })
                _this.setData({
                    "loading": false,
                    "nodata": true
                })
            }
            wx.hideLoading();
        })
    },
    //滚动加载
    lower: function (e) {
        var _this = this;
        var page = _this.data.page + 1;
        if (page <= _this.data.totalpage) {
            _this.setData({
                "page": page,
                "loading": true,
                "loadingconflg": true,
            })
            _this.GetList();
        } else {
            _this.setData({
                "loading": true,
                "loadingconflg": false,
            })
        }
    },
    //跳转到详情页面
    ToDetail: function (e) {
        console.log(e);
        var dataset = e.currentTarget.dataset;
        wx.navigateTo({
            url: 'yetmentdetail?id=' + dataset.id,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    //获取列表信息 
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        var userInfo = app.globalData.userInfo;
        //判断当前用户是否开通服务,开通则分享美名片页,否则分享访问记录页
        if (userInfo == null || typeof (userInfo) == "undefined") {
            app.getUserall(function (res) {
                userInfo = res;
            });
        }
        var path = userInfo.UserType == 2 ? "/pages/index/index?cid=" + userInfo.Id : "/pages/cardrecord/cardrecord";
        return {
            title: userInfo.NickName + "的美名片",
            path: path,
            success: function (res) {
                wx.showToast({
                    title: '分享成功',
                    icon: "success",
                    duration: 200
                })
            }
        }
    }
})